<template>
  <div class="playlist-tag">
    <div class="tagbtn" @click="isShowAllTag= true">
      {{chooseTag | tagAll}}<span class="el-icon-arrow-right"></span>
    </div>
    <!-- 标签详情-->
    <div class="all-tag" v-show="isShowAllTag" @click="isShowAllTag= false">
      <!-- 全部歌单 -->
      <div class="allplaylist">
        <div class="allplaylist-content" @click="setTag('全部')" :class="{active: chooseTag == '全部'}">全部歌单</div>
      </div>
      <!-- 第一类标签 -->
      <div class="language tag-content">
        <div class="categories"><span class="iconfont icon-diqiuquanqiu"></span>
          <p>{{categories[0]}}</p>
        </div>
        <ul class="tag tag-content">
          <li @click="setTag(item.name)" v-for="(item,index) of category0" :key="index+'category0'">
            <div class="text-style" :class="{active: chooseTag ==item.name}">{{item.name}}</div>
          </li>
        </ul>
      </div>
      <!-- 第二类标签 -->
      <div class="style tag-content">
        <div class="categories"><span class="iconfont icon-gangqin"></span>
          <p>{{categories[1]}}</p>
        </div>
        <ul class="tag tag-content">
          <li @click="setTag(item.name)" v-for="(item,index) of category1" :key="index+'category1'">
            <div class="text-style" :class="{active: chooseTag ==item.name}">{{item.name}}</div>
          </li>
        </ul>
      </div>
      <!-- 第三类标签 -->
      <div class="scene tag-content">
        <div class="categories"><span class="iconfont icon-kafei"></span>
          <p>{{categories[2]}}</p>
        </div>
        <ul class="tag tag-content">
          <li @click="setTag(item.name)" v-for="(item,index) of category2" :key="index+'category2'">
            <div class="text-style" :class="{active: chooseTag ==item.name}">{{item.name}}</div>
          </li>
        </ul>
      </div>
      <!-- 第四类标签 -->
      <div class="emotion tag-content">
        <div class="categories"><span class="iconfont icon-Emotion"></span>
          <p>{{categories[3]}}</p>
        </div>
        <ul class="tag tag-content">
          <li @click="setTag(item.name)" v-for="(item,index) of category3" :key="index+'category3'">
            <div class="text-style" :class="{active: chooseTag ==item.name}">{{item.name}}</div>
          </li>
        </ul>
      </div>
      <!-- 第五类标签 -->
      <div class="theme tag-content">
        <div class="categories"><span class="iconfont icon-zhuti"></span>
          <p>{{categories[4]}}</p>
        </div>
        <ul class="tag tag-content">
          <li @click="setTag(item.name)" v-for="(item,index) of category4" :key="index+'category4'">
            <div class="text-style" :class="{active: chooseTag ==item.name}">{{item.name}}</div>
          </li>
        </ul>
      </div>
    </div>
    <!-- 热门标签 -->
    <div class="tag-text">
      <ul>
        <li v-for="(item,index) of Hotcategory" :key="index+'hotcategory'" @click="setTag(item.name)">{{item.name}}</li>
      </ul>
    </div>
  </div>
</template>
<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { getplaylistcatlistAPI, gethotplaylistAPI } from "@/api/playlist";
export default {
  name: "playlist-tag",
  //import引入的组件需要注入到对象中才能使用
  components: {},
  props: {
    chooseTag: {
      require: true,
    },
  },
  data() {
    //这里存放数据
    return {
      tag: "",
      //歌单种类
      categories: {},
      // 数据分类详情
      category0: [],
      category1: [],
      category2: [],
      category3: [],
      category4: [],
      // 热门分类
      Hotcategory: [],
      // 控制显示隐藏
      isShowAllTag: false,
    };
  },
  //计算属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    // 获取歌单分类
    async getplaylistcatlist() {
      const { data } = await getplaylistcatlistAPI();
      // 根据字符串进行存储
      let category = {
        category0: this.category0,
        category1: this.category1,
        category2: this.category2,
        category3: this.category3,
        category4: this.category4,
      };
      this.categories = data.categories;
      data.sub.forEach((ele) => {
        let name = "category" + ele.category;
        category[name].push(ele);
        // if (ele.hot == true) {
        //   this.Hotcategory.push(ele);
        // }
      });
    },
    // 热门标签
    async gethotplaylist() {
      const { data } = await gethotplaylistAPI();
      this.Hotcategory = data.tags;
    },
    // 设置标签
    setTag(tag) {
      this.$emit("changetag", tag);
      // this.isShowAllTag = false;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getplaylistcatlist();
    this.gethotplaylist();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style scoped lang='less'>
.playlist-tag {
  position: relative;
  display: flex;
  justify-content: space-between;
  .all-tag {
    position: absolute;
    z-index: 1;
    top: 40px;
    width: 740px;
    background-color: white;
    box-shadow: 0 0 5px rgb(160, 160, 160);
    border-radius: 5px;
    .allplaylist {
      position: relative;
      height: 50px;
      border-bottom: 1px solid rgb(204, 204, 204);

      .allplaylist-content {
        position: absolute;
        top: 10px;
        left: 20px;
        height: 30px;
        width: 100px;
        text-align: center;
        line-height: 30px;
        color: rgb(27, 27, 27);
        border: 1px solid transparent;
        border-radius: 30px;
        cursor: pointer;
      }
      .active {
        color: rgb(62, 194, 255);
        background-color: rgb(238, 247, 253);
      }
    }
    ul {
      width: 600px;
      flex-shrink: 0;
      display: flex;
      li {
        cursor: pointer;
        color: rgb(27, 27, 27);
        flex-shrink: 0;
        list-style: none;
        height: 50px;
        line-height: 50px;
        width: 110px;
        .text-style {
          display: inline-block;
          height: 30px;
          line-height: 30px;
          padding-left: 10px;
          padding-right: 10px;
        }
        .active {
          color: rgb(62, 194, 255);
          background-color: rgb(238, 247, 253);
          border-radius: 30px;
        }
      }
      li:hover {
        color: rgb(129, 205, 255);
      }
    }
    .tag-content {
      display: flex;
      flex-wrap: wrap;
    }
    .categories {
      display: flex;
      font-size: 17px;
      color: rgb(153, 153, 153);
      width: 120px;
      margin-left: 15px;
      flex-shrink: 0;
      cursor: default;
      .iconfont {
        font-size: 30px;
        font-weight: 500;
        height: 50px;
        line-height: 50px;
      }
      p {
        display: inline-block;
        height: 50px;
        line-height: 50px;
      }
    }
  }
  .tagbtn {
    border: 1px solid rgb(156, 156, 156);
    height: 30px;
    width: 120px;
    line-height: 29px;
    border-radius: 30px;
    font-size: 15px;
    text-align: center;
    color: rgb(73, 73, 73);
    cursor: pointer;
  }
  .tagbtn:hover {
    background-color: rgb(240, 240, 240);
  }
  .tag-text {
    ul {
      list-style: none;
      height: 30px;
      line-height: 30px;
      li {
        cursor: default;
        display: inline;
        margin: 0 5px 0 5px;
        color: rgb(128, 128, 128);
      }
      li:hover {
        color: rgb(44, 44, 44);
      }
    }
  }
}
</style>